package com.lottery.ruok.lottrey.activity;

import android.animation.Animator;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.google.gson.Gson;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.adapter.ChangLongFragmentAdapter;
import com.lottery.ruok.lottrey.adapter.HexiaoAdapterAdapter;
import com.lottery.ruok.lottrey.adapter.LiuhecaiDetailListView;
import com.lottery.ruok.lottrey.adapter.LiuhecaiMainAdapter;
import com.lottery.ruok.lottrey.adapter.MyPagerAdapter;
import com.lottery.ruok.lottrey.adapter.PrizeListAdapter;
import com.lottery.ruok.lottrey.bean.LiuheBean;
import com.lottery.ruok.lottrey.bean.QuickChoose;
import com.lottery.ruok.lottrey.dialog.LiuhecaiTypeDialog;
import com.lottery.ruok.lottrey.eventbusObject.AddBetList;
import com.lottery.ruok.lottrey.eventbusObject.AddBetSuccess;
import com.lottery.ruok.lottrey.eventbusObject.ChangLongRefrash;
import com.lottery.ruok.lottrey.eventbusObject.GetAccountWithPush;
import com.lottery.ruok.lottrey.eventbusObject.LoginSuccess;
import com.lottery.ruok.lottrey.eventbusObject.PrizePushInfo;
import com.lottery.ruok.lottrey.eventbusObject.StartPrzePush;
import com.lottery.ruok.lottrey.fragment.ChangLongFragment;
import com.lottery.ruok.lottrey.interfaces.LiuhecaiDetailListWatch;
import com.lottery.ruok.lottrey.retrofitModule.RetrofitBase;
import com.lottery.ruok.lottrey.retrofitModule.RxHelper;
import com.lottery.ruok.lottrey.retrofitModule.RxSubscribe;
import com.lottery.ruok.lottrey.retrofitModule.request.GetChatRoomCurrentStatus;
import com.lottery.ruok.lottrey.retrofitModule.request.GetCurrentIssueNoRequest;
import com.lottery.ruok.lottrey.retrofitModule.request.GetLotteryDetailRequest;
import com.lottery.ruok.lottrey.retrofitModule.request.GetPrizeHistoryRequest;
import com.lottery.ruok.lottrey.retrofitModule.response.ChatRoomStatus;
import com.lottery.ruok.lottrey.retrofitModule.response.GetCurrentIssueNoResponse;
import com.lottery.ruok.lottrey.retrofitModule.response.GetLotteryDetailResponse;
import com.lottery.ruok.lottrey.retrofitModule.response.GetPrizeHistroyResponse;
import com.lottery.ruok.lottrey.retrofitModule.response.GetProfileResponse;
import com.lottery.ruok.lottrey.ui.BottomOrderLayout;
import com.lottery.ruok.lottrey.ui.component.BuyLotteryTopView;
import com.lottery.ruok.lottrey.ui.component.LHCLeftMenuView;
import com.lottery.ruok.lottrey.ui.widget.TabSelect;
import com.lottery.ruok.lottrey.userInfo.UserInfo;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.observers.DisposableObserver;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import ui.NoScrollGridView;
import utils.Utils;

//import ui.IToastBell;
/*
 * 六合彩票投注大厅详情页
 *
 *
 * */

public class LiuhecaiDetailActivity extends BaseActivity implements SensorEventListener {
    private static final String EXTRA_CODE = "code";
    private static final int WHAT_REFRESH_TIME = 10;
    @BindView(R.id.webview_random)
    WebView webviewRandom;
    @BindView(R.id.anim_view)
    LottieAnimationView animView;
    @BindView(R.id.shadow)
    ImageView shadow;
    @BindView(R.id.issue)
    TextView issue;
    @BindView(R.id.downtime)
    TextView downtime;
    @BindView(R.id.start_prize)
    LinearLayout recentPrize;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.odd)
    TextView oddTotal;
    @BindView(R.id.webview)
    WebView webView;
    @BindView(R.id.prize_list)
    ListView prizeList;
    @BindView(R.id.container)
    LinearLayout container;
    @BindView(R.id.anim_prize)
    LottieAnimationView animPrize;
    @BindView(R.id.ball_view)
    ImageView ball_view;
    @BindView(R.id.method_name)
    TextView method_name;
    @BindView(R.id.iv_refresh)
    ImageView ivRefresh;
    @BindView(R.id.view_refresh_animation)
    LottieAnimationView viewRefreshAnimation;
    @BindView(R.id.view_refresh)
    FrameLayout viewRefresh;
    @BindView(R.id.buy_lottery_top)
    BuyLotteryTopView buyLotteryTop;
    @BindView(R.id.tab_select)
    TabSelect mTabSelect;
    @BindView(R.id.ll_liu_he_select1)
    LinearLayout llLiuHeSelect1;
    @BindView(R.id.ll_liu_he_select2)
    LinearLayout llLiuHeSelect2;
    @BindView(R.id.tabs2)
    TabLayout tabs2;
    @BindView(R.id.viewPager2)
    ViewPager viewPager2;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case WHAT_REFRESH_TIME:
                    ivRefresh.setEnabled(true);
                    ivRefresh.setSelected(true);

                    break;
            }
        }
    };


    public GetLotteryDetailResponse getLotteryDetailResponse;
    private int totalMoneys;//总钱数用于跟余额比较
    private boolean mIsPrizeTime;//是否处于开奖状态
    private int mIndex = 0;
    private CountDownTimer countDownTimer;
    private ArrayList<ArrayList<LiuheBean>> liuheItems;
    private float[] hexiaoOdds;
    private int whichTabNo = 0;//当前的焦点索引
    private LiuhecaiDetailListView zhengmaguoguanAdapter;
    private ArrayList<LiuhecaiMainAdapter> myAdapters = new ArrayList<>();
    private ArrayList<GridView> myGridViews = new ArrayList<>();
    private ListView zhengmaguoguanListView;
    private SensorManager mSensorManager;
    private Vibrator mVibrator;//手机震动
    private boolean isShake = false;//记录摇动状态
    private MyHandler mHandler;
    private static final int START_SHAKE = 0x1;
    private static final int AGAIN_SHAKE = 0x2;
    private static final int END_SHAKE = 0x3;
    public String ANALYTIC_VERSION = "1.0";
    private Runnable issueRunnable;
    private BottomOrderLayout mBottomOrderLayout;
    private Runnable errorRunnable;
    private ArrayList<GetPrizeHistroyResponse> getPrizeHistroyResponses = new ArrayList<>();
    private String lotteryCode;

    LHCLeftMenuView.OnLHCLeftClickListener onLHCLeftClickListener = new LHCLeftMenuView.OnLHCLeftClickListener() {
        @Override
        public void onClick(String text) {
            int tempPosition = 0;

            switch (text) {
                case "单":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = Integer.parseInt(liuheItems.get(whichTabNo).get(i).number) % 2 == 1;
                    }
                    tempPosition = 0;
                    break;
                case "双":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = Integer.parseInt(liuheItems.get(whichTabNo).get(i).number) % 2 != 1;
                    }
                    tempPosition = 0;
                    break;
                case "大"://大：号码 >= 25
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = Integer.parseInt(liuheItems.get(whichTabNo).get(i).number) >= 25;
                    }
                    tempPosition = 24;
                    break;
                case "小":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = Integer.parseInt(liuheItems.get(whichTabNo).get(i).number) < 25;
                    }
                    tempPosition = 0;
                    break;
                case "0头":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = liuheItems.get(whichTabNo).get(i).number.startsWith("0");
                    }
                    tempPosition = 0;
                    break;
                case "1头":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = liuheItems.get(whichTabNo).get(i).number.startsWith("1");
                    }
                    tempPosition = 9;
                    break;
                case "2头":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = liuheItems.get(whichTabNo).get(i).number.startsWith("2");
                    }
                    tempPosition = 19;
                    break;
                case "3头":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = liuheItems.get(whichTabNo).get(i).number.startsWith("3");
                    }
                    tempPosition = 29;
                    break;
                case "4头":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = liuheItems.get(whichTabNo).get(i).number.startsWith("4");
                    }
                    tempPosition = 39;
                    break;
                case "红":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = getLotteryDetailResponse.getColor().getRed().indexOf(liuheItems.get(whichTabNo).get(i).number) != -1;
                    }
                    tempPosition = 0;
                    break;
                case "绿":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = getLotteryDetailResponse.getColor().getGreen().indexOf(liuheItems.get(whichTabNo).get(i).number) != -1;
                    }
                    tempPosition = 0;
                    break;
                case "蓝":
                    for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                        liuheItems.get(whichTabNo).get(i).choose = getLotteryDetailResponse.getColor().getBlue().indexOf(liuheItems.get(whichTabNo).get(i).number) != -1;
                    }
                    tempPosition = 0;
                    break;
                default:
                    tempPosition = 0;
                    break;
            }
            myAdapters.get(whichTabNo).notifyDataSetChanged();
            final int finalTempPosition = tempPosition;
            myGridViews.get(whichTabNo).post(new Runnable() {
                @Override
                public void run() {
                    myGridViews.get(whichTabNo).setSelection(finalTempPosition);
                }
            });
            getMoney();
        }

    };

    private void gotoShoppingCar() {
        if ((!downtime.getText().toString().startsWith("00:00:") && getIntent().getStringExtra("code").equals("xglhc")) || (!downtime.getText().toString().startsWith("00:00:0") && getIntent().getStringExtra("code").equals("jslhc"))|| (!downtime.getText().toString().startsWith("00:00:0") && getIntent().getStringExtra("code").equals("js10flhc"))) {//如果倒计时小于60秒，不能购买彩票。又加入了极速六合彩，提前十秒才可以买
            if (LHCBetListActivity.liuheBeanArrayList.size() > 0) {
                Intent intent = new Intent(this, LHCBetListActivity.class);
                intent.putExtra("colors", getLotteryDetailResponse.getColor());
                intent.putExtra("code", getIntent().getStringExtra("code"));
                intent.putExtra("shopping_car", true);
                startActivity(intent);
            } else {
                Utils.showToast("目前注单为0");
            }
        } else {
            Utils.showToast("当前状态不可购买");
        }
    }

    @Override
    protected void onStart() {
        super.onStart();

        mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));//获取 SensorManager 负责管理传感器
        if (mSensorManager != null) {
            Sensor mAccelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);//获取加速度传感器
            if (mAccelerometerSensor != null) {
                mSensorManager.registerListener(this, mAccelerometerSensor, SensorManager.SENSOR_DELAY_UI);
            }
        }
    }

    @Override
    protected void onPause() {
        if (mSensorManager != null) {// 务必要在pause中注销 mSensorManager,否则会造成界面退出后摇一摇依旧生效的bug
            mSensorManager.unregisterListener(this);
        }

        super.onPause();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(GetAccountWithPush getAccountWithPush) {
        mBottomOrderLayout.setLoginState();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(PrizePushInfo event) {
        if (event.getCode() != null && getIntent().getStringExtra("code") != null) {
            if (event.getCode().equals(getIntent().getStringExtra("code"))) {
                getPrizeHistory(false);
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(StartPrzePush event) {
        setTimer(false, false);
        getPrizeHistory(false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_liuhecai_detail);
        ButterKnife.bind(this);
        if (getIntent() != null) {
            lotteryCode = getIntent().getStringExtra("code");
        }
        if (lotteryCode.equals("jslhc")||lotteryCode.equals("js10flhc")) {
            mTabSelect.setVisibility(View.VISIBLE);
        } else {
            mTabSelect.setVisibility(View.GONE);
        }
        init();
        if (Utils.isEmpty(UserInfo.getToken())) {
            //未登录
            viewRefresh.setVisibility(View.GONE);
            viewRefresh.setSelected(false);
        } else {
            viewRefresh.setVisibility(View.VISIBLE);
            viewRefresh.setSelected(true);
        }
        buyLotteryTop.setBuyLotteryTopViewListener(new BuyLotteryTopView.BuyLotteryTopViewListener() {
            @Override
            public void tabOnClick(int type) {
                switch (type) {
                    //1back，2彩票名称，3投注记录，4走势，5规则
                    case 1:
                        finish();
                        break;
                    case 2:
                        ChooseLotteryActivity.startActivity(LiuhecaiDetailActivity.this, getIntent().getStringExtra("code"));
                        break;
                    case 3:
                        gotoOrderList();
                        break;
                    case 4:
                        gotoPrizeList();
                        break;
                    case 5:
                        gotoRule();
                        break;

                }
            }
        });
        getRoomStatus();
        if (UserInfo.getChatStatus() == ChatRoomStatus.CHAT_ROOM_STATUS_OPEN) {
            ball_view.setVisibility(View.VISIBLE);
        } else if (UserInfo.getChatStatus() == ChatRoomStatus.CHAT_ROOM_STATUS_CLOSE) {
            ball_view.setVisibility(View.GONE);
        }
//        getRoomStatus();
        //两面长龙模块
        initChangLong();

    }

    private void initChangLong() {
        ArrayList<String> titleDatas = new ArrayList<>();
        titleDatas.add("两面长龙");
        ArrayList<android.support.v4.app.Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new ChangLongFragment());


        final ChangLongFragmentAdapter changLongFragmentAdapter = new ChangLongFragmentAdapter(getSupportFragmentManager(), fragmentList);
        viewPager2.setAdapter(changLongFragmentAdapter);
        tabs2.setupWithViewPager(viewPager2);
        viewPager2.setOffscreenPageLimit(3);
        tabs2.setTabsFromPagerAdapter(changLongFragmentAdapter);
        for (int i = 0; i < changLongFragmentAdapter.getCount(); i++) {
            TabLayout.Tab tab = tabs2.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(getTabView(titleDatas.get(i), i));
            }
        }
        viewPager2.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                for (int i = 0; i < changLongFragmentAdapter.getCount(); i++) {
                    if (i == position) {
                        tabs2.getTabAt(i).getCustomView().findViewById(R.id.imageView).setVisibility(View.VISIBLE);
                    } else {
                        tabs2.getTabAt(i).getCustomView().findViewById(R.id.imageView).setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    private View getTabView(String s, int position) {
        View view = LayoutInflater.from(this).inflate(R.layout.tab_item, null);
        TextView tv = view.findViewById(R.id.textView);
        tv.setText(s);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        if (position == 0) {
            view.findViewById(R.id.imageView).setVisibility(View.VISIBLE);
        }
        return view;
    }

    public void chooseType(int index) {
        mIndex = index;
        whichTabNo = 0;
        setDatas();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        EventBus.getDefault().unregister(this);

        if (countDownTimer != null) {
            countDownTimer.cancel();
            countDownTimer = null;
        }

        if (issueRunnable != null) {
            issue.removeCallbacks(issueRunnable);
        }
        if (errorRunnable != null) {
            issue.removeCallbacks(errorRunnable);
        }
    }

    private void setTimer(final boolean isBegin, final boolean fromPrize) {//fromPrize表示来自于开奖开出来的回调，当奖开出来之后，fromPrize为true，不会再调用一次getPrizeHistory
        RetrofitBase.getRetrofit().create(GetCurrentIssueNoRequest.class).getResult(getIntent().getStringExtra("code"))
                .compose(RxHelper.<GetCurrentIssueNoResponse>handleResultReConnection())
                .subscribe(new RxSubscribe<GetCurrentIssueNoResponse>(this) {
                    @Override
                    protected void _onNext(final GetCurrentIssueNoResponse getCurrentIssueNoResponse) {
                        if (countDownTimer != null) {
                            countDownTimer.cancel();
                            countDownTimer = null;
                        }

                        if (!isBegin) {
                            if (getCurrentIssueNoResponse.getTime() == 0) {
                                return;
                            }
                        }

                        issue.setText("距" + getCurrentIssueNoResponse.getNo() + "期开奖");

                        //启动定时器
                        countDownTimer = new CountDownTimer(getCurrentIssueNoResponse.getTime() * 1000, 1000) {
                            @Override
                            public void onTick(long l) {
                                downtime.setText(Utils.getCountTimeByLong(l));
                            }

                            @Override
                            public void onFinish() {
                                downtime.setText("00:00:00");

//                                IToastBell.show("期次已变化，当前期次是" + (Long.parseLong(getCurrentIssueNoResponse.getNo()) + 1), LiuhecaiDetailActivity.this);

                                if (getPrizeHistroyResponses.size() > 0) {
                                    getPrizeHistroyResponses.remove(getPrizeHistroyResponses.size() - 1);
                                    GetPrizeHistroyResponse getPrizeHistroyResponse = new GetPrizeHistroyResponse();
                                    getPrizeHistroyResponse.setIssue_no(getCurrentIssueNoResponse.getNo());
                                    getPrizeHistroyResponse.setPrize_num("");
                                    getPrizeHistroyResponses.add(0, getPrizeHistroyResponse);
                                }
                                handlePrizeData(false);

                                issueRunnable = new IssueRunnable(LiuhecaiDetailActivity.this, fromPrize);
                                issue.postDelayed(issueRunnable, 2000);
                            }
                        };
                        countDownTimer.start();
                    }

                    @Override
                    protected boolean showDialog() {
                        return true;
                    }
                });
    }

    int totalNum = 0;//自选不中，连肖，连码，连尾，中一的总注数
    int totalNums[] = null;//存放每种tab的注数个数

    @JavascriptInterface
    public void count(final int count, final int index) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                totalNum += count;
                totalNums[index] = count;

                int my;
                if (!mBottomOrderLayout.getMoney_and_num().getText().toString().equals("")) {
                    my = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                } else {
                    my = 0;
                }
                if (totalNum > 0) {
                    mBottomOrderLayout.bottomShowState2();
                } else {
                    mBottomOrderLayout.bottomShowState1();
                }
                mBottomOrderLayout.getNumAndMoney().setText(totalNum + "种组合    " + my * totalNum + "元");
                totalMoneys = my * totalNum;
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent1(AddBetList addBetList) {
        setDatas();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent1(AddBetSuccess addBetSuccess) {
        if (addBetSuccess.getAfter_amount() != null) {
            UserInfo.setAccount(addBetSuccess.getAfter_amount());
            mBottomOrderLayout.setLoginState();
        } else {
            updateAccount(new AfterUpdateAccount() {
                @Override
                public void afterUpdateAccount(GetProfileResponse getProfileResponse) {
                    UserInfo.setAccount(getProfileResponse.getUser().getAccount());
                    mBottomOrderLayout.setLoginState();
                }
            });
        }
        if (Utils.isEmpty(UserInfo.getToken())) {
            //未登录
            viewRefresh.setVisibility(View.GONE);
            viewRefresh.setSelected(false);
        } else {
            viewRefresh.setVisibility(View.VISIBLE);
            viewRefresh.setSelected(true);
        }
//        Intent intent = new Intent(this, OrderActivity.class);
//        intent.putExtra("from_buy", true);
//        startActivity(intent);
    }

    @Override
    public void finish() {
        super.finish();

        LHCBetListActivity.liuheBeanArrayList.clear();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(LoginSuccess event) {
        mBottomOrderLayout.setLoginState();
        getRedPacketNum(ball_view);
    }

    private void init() {
        getRedPacketNum(ball_view);

        Disposable observer = LHCBetListActivity.liuheBeanArrayList.getObservable().subscribe(new Consumer<ArrayList<LHCBetListActivity.Results>>() {
            @Override
            public void accept(final ArrayList<LHCBetListActivity.Results> results) {
                mBottomOrderLayout.getInclude_note_count().setText(results.size() + "");
            }
        });
        disposables.add(observer);

        mBottomOrderLayout = new BottomOrderLayout(this,
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        if (!Utils.isFastDoubleClick()) {
                            startShake();
                        }
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        setDatas();
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        if (getLotteryDetailResponse != null
                                && getLotteryDetailResponse.getLayouts() != null
                                && getLotteryDetailResponse.getLayouts().get(mIndex) != null
                                && getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code() != null) {
                            if ("hexiao".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                setHexiaoMoney();
                            } else {
                                getMoney();
                            }
                        }
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        confirm(true);
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        gotoShoppingCar();
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        confirm(false);
                        return null;
                    }
                }, false,
                null,
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        gotoLoginActivity();
                        return null;
                    }
                },
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                  //      gotoSummaryActivity();
                        startActivity(new Intent(LiuhecaiDetailActivity.this, OrderActivity.class));
                        return null;
                    }
                });

        container.setPadding(0, Utils.dip2px(LiuhecaiDetailActivity.this, 12), 0, Utils.dip2px(LiuhecaiDetailActivity.this, 12));
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) container.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
        layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
        container.setLayoutParams(layoutParams);

        mHandler = new MyHandler(this);
        //获取Vibrator震动服务
        mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

        EventBus.getDefault().register(this);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("file:///android_asset/count.html");
        webView.addJavascriptInterface(this, "MyCount");

        webviewRandom.getSettings().setJavaScriptEnabled(true);
        webviewRandom.loadUrl("file:///android_asset/selectapi.html");
        webviewRandom.addJavascriptInterface(this, "MyCount");

        setTimer(true, false);

        getLotteryDetail(true);

        getPrizeHistory(true);
        mTabSelect.setTabSelectListener(new TabSelect.TabSelectListener() {
            @Override
            public void tabOnClick(int selected) {
                switch (selected) {
                    case TabSelect.TabSelectListener.SELECT_TAB1:
                        llLiuHeSelect2.setVisibility(View.GONE);
                        llLiuHeSelect1.setVisibility(View.VISIBLE);
                        //IToast.show("普通模式",ChuantongcaiActivity.this);
                        isShake = false;
                        break;
                    case TabSelect.TabSelectListener.SELECT_TAB2:
                        llLiuHeSelect1.setVisibility(View.GONE);
                        llLiuHeSelect2.setVisibility(View.VISIBLE);
                        // IToast.show("长龙遗漏模式",ChuantongcaiActivity.this);
                        isShake = true;
                        break;
                }
            }
        });
    }

    private void getLotteryDetail(final boolean progress) {
        DisposableObserver disposableObserver = RetrofitBase.getRetrofit().create(GetLotteryDetailRequest.class).getResult(getIntent().getStringExtra("code"), UserInfo.getToken())
                .compose(RxHelper.<GetLotteryDetailResponse>handleResult())
                .subscribeWith(new RxSubscribe<GetLotteryDetailResponse>(this) {
                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                        errorRunnable = new Runnable() {
                            @Override
                            public void run() {
                                getLotteryDetail(false);
                            }
                        };
                        issue.postDelayed(errorRunnable, 1000);
                    }

                    @Override
                    protected void _onNext(GetLotteryDetailResponse g) {
                        getLotteryDetailResponse = g;

                        if (getLotteryDetailResponse != null && getLotteryDetailResponse.getRemaining_balance() != null) {
                            if (!UserInfo.getToken().equals("")) {
                                UserInfo.setAccount(getLotteryDetailResponse.getRemaining_balance());
                                mBottomOrderLayout.setLoginState();
                            }
                        }

                        if (getLotteryDetailResponse != null) {
                            buyLotteryTop.setLotteryName(getLotteryDetailResponse.getName());
                        }

                        for (int i = 0; i < getLotteryDetailResponse.getLayouts().size(); i++) {
                            if (getLotteryDetailResponse.getLayouts().get(i).getSelected().equals("1")) {
                                mIndex = i;
                                break;
                            }
                        }

                        chooseType(mIndex);
                    }

                    @Override
                    protected boolean showDialog() {
                        return progress;
                    }
                });
        disposables.add(disposableObserver);
    }

    private void startPrizeAnimation(final ArrayList<LottieAnimationView> lottieAnimationViews, final int index, final ArrayList<TextView> animals, final ArrayList<TextView> numbers) {
        if (lottieAnimationViews.size() > index) {
            lottieAnimationViews.get(index).playAnimation();
            lottieAnimationViews.get(index).addAnimatorListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {

                }

                @Override
                public void onAnimationEnd(Animator animator) {
                    animals.get(index).setVisibility(View.VISIBLE);
                    numbers.get(index).setVisibility(View.VISIBLE);

                    startPrizeAnimation(lottieAnimationViews, index + 1, animals, numbers);
                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            });
        }
    }

    public static void startActivity(Activity activity, String code) {
        Intent intent = new Intent(activity, LiuhecaiDetailActivity.class);
        intent.putExtra(EXTRA_CODE, code);
        activity.startActivity(intent);
    }

    private static class IssueRunnable implements Runnable {
        private WeakReference<LiuhecaiDetailActivity> mReference;
        private boolean fromPrize;

        public IssueRunnable(LiuhecaiDetailActivity newLotteryDetailActivity, boolean fromPrize) {
            mReference = new WeakReference(newLotteryDetailActivity);
            this.fromPrize = fromPrize;
        }

        @Override
        public void run() {
            if (mReference != null && mReference.get() != null) {
                mReference.get().setTimer(false, false);
//                if(!fromPrize) {
//                    mReference.get().getPrizeHistory(false);
//                }
            }
        }
    }

    private void handlePrizeData(boolean isBegin) {
        if (getPrizeHistroyResponses.size() > 0) {
            String[] p = getPrizeHistroyResponses.get(0).getPrize_num().split(",");
            if (p.length > 0 && !p[0].equals("")) {
                container.removeAllViews();
                ArrayList<LottieAnimationView> lottieAnimationViews = new ArrayList();
                ArrayList<TextView> numbers = new ArrayList();
                ArrayList<TextView> animals = new ArrayList();
                if (getPrizeHistroyResponses.get(0).getAttached() != null && p.length == getPrizeHistroyResponses.get(0).getAttached().getColor().size()) {
                    for (int i = 0; i < p.length; i++) {
                        FrameLayout frameLayout = new FrameLayout(LiuhecaiDetailActivity.this);
                        FrameLayout.LayoutParams frameLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        frameLayout.setLayoutParams(frameLayoutParams);

                        TextView areaCircle = new TextView(LiuhecaiDetailActivity.this);
                        areaCircle.setText(p[i]);
                        areaCircle.setVisibility(View.INVISIBLE);
                        areaCircle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                        areaCircle.setTypeface(null, Typeface.BOLD);
                        areaCircle.setTextColor(Color.parseColor("#3f3f3f"));
                        numbers.add(areaCircle);

                        LinearLayout linearLayout = new LinearLayout(LiuhecaiDetailActivity.this);
                        linearLayout.setOrientation(LinearLayout.VERTICAL);
                        linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
                        linearLayout.addView(frameLayout);

                        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        layoutParams.gravity = Gravity.CENTER;
                        areaCircle.setLayoutParams(layoutParams);

                        LottieAnimationView lottieAnimationView = new LottieAnimationView(LiuhecaiDetailActivity.this);
                        if (getPrizeHistroyResponses.get(0).getAttached().getColor().get(i).equals("blue")) {
                            lottieAnimationView.setImageAssetsFolder("bo/blue/images");
                            lottieAnimationView.setAnimation("bo/blue/blue.json");
                        } else if (getPrizeHistroyResponses.get(0).getAttached().getColor().get(i).equals("red")) {
                            lottieAnimationView.setImageAssetsFolder("bo/red/images");
                            lottieAnimationView.setAnimation("bo/red/red.json");
                        } else if (getPrizeHistroyResponses.get(0).getAttached().getColor().get(i).equals("green")) {
                            lottieAnimationView.setImageAssetsFolder("bo/green/images");
                            lottieAnimationView.setAnimation("bo/green/green.json");
                        }
                        lottieAnimationViews.add(lottieAnimationView);

                        FrameLayout.LayoutParams layoutParamsQiu = new FrameLayout.LayoutParams(Utils.dip2px(LiuhecaiDetailActivity.this, 35), Utils.dip2px(LiuhecaiDetailActivity.this, 35));
                        layoutParamsQiu.gravity = Gravity.CENTER;
                        lottieAnimationView.setLayoutParams(layoutParamsQiu);
                        frameLayout.addView(lottieAnimationView);
                        frameLayout.addView(areaCircle);

                        TextView textView = new TextView(LiuhecaiDetailActivity.this);
                        if (getPrizeHistroyResponses.size() > 0 && getPrizeHistroyResponses.get(0).getAttached().getSx().size() > 0) {
                            textView.setText(getPrizeHistroyResponses.get(0).getAttached().getSx().get(i));
                            textView.setVisibility(View.INVISIBLE);
                            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
                            textView.setTextColor(Color.parseColor("#3f3f3f"));
                            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                            textView.setLayoutParams(layoutParams1);
                            animals.add(textView);
                        }

                        linearLayout.addView(textView);
                        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        layoutParams2.rightMargin = Utils.dip2px(LiuhecaiDetailActivity.this, 3);
                        linearLayout.setLayoutParams(layoutParams2);
                        container.addView(linearLayout);

                        if (i == p.length - 2) {//倒数第二个
                            TextView add = new TextView(LiuhecaiDetailActivity.this);
                            add.setTextColor(Color.parseColor("#dfdfdf"));
                            add.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
                            add.setText("+");
                            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
                            layoutParams1.rightMargin = Utils.dip2px(LiuhecaiDetailActivity.this, 3);
                            layoutParams1.weight = 1.0f;
                            layoutParams1.gravity = Gravity.TOP;
                            add.setLayoutParams(layoutParams1);
                            container.addView(add);
                        }
                    }
                }
                if (prizeList.getVisibility() != View.VISIBLE) {
                    container.setVisibility(View.VISIBLE);
                    animPrize.setVisibility(View.GONE);
                    animPrize.pauseAnimation();
                    //发送更新的eventbus
                    if (lotteryCode.equals("jslhc")||lotteryCode.equals("js10flhc")) {
                        EventBus.getDefault().post(new ChangLongRefrash());
                    }
                }
                startPrizeAnimation(lottieAnimationViews, 0, animals, numbers);

                mIsPrizeTime = false;

                if (!isBegin) {
                    setTimer(false, true);
                }
            } else {
                setPrizeState();
            }

            prizeList.setAdapter(new PrizeListAdapter(getPrizeHistroyResponses, LiuhecaiDetailActivity.this, getIntent().getStringExtra("code"), mIsPrizeTime));
        }
    }

    private void getPrizeHistory(final boolean isBegin) {
        DisposableObserver disposableObserver = RetrofitBase.getRetrofit().create(GetPrizeHistoryRequest.class).getResult(getIntent().getStringExtra("code"))
                .compose(RxHelper.<ArrayList<GetPrizeHistroyResponse>>handleResultReConnection())
                .subscribeWith(new RxSubscribe<ArrayList<GetPrizeHistroyResponse>>(this) {
                    @Override
                    protected void _onNext(ArrayList<GetPrizeHistroyResponse> g) {
                        getPrizeHistroyResponses.clear();
                        getPrizeHistroyResponses.addAll(g);

                        handlePrizeData(isBegin);
                    }

                    @Override
                    protected boolean showDialog() {
                        return false;
                    }
                });
        disposables.add(disposableObserver);
    }

    private void setPrizeState() {
        if (prizeList.getVisibility() != View.VISIBLE) {
            container.setVisibility(View.GONE);
            animPrize.setVisibility(View.VISIBLE);
            animPrize.resumeAnimation();
        }
        mIsPrizeTime = true;
    }

    private void itemClicks(final GridView gridView, final int position, final int max) {
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) {
                if (liuheItems.get(position).get(j).choose) {
                    liuheItems.get(position).get(j).choose = false;
                } else {
                    int sum = 0;
                    for (LiuheBean liuheBean : liuheItems.get(position)) {
                        if (liuheBean.choose) {
                            sum++;
                        }
                    }
                    if (sum < max) {
                        liuheItems.get(position).get(j).choose = true;
                    } else {
                        Utils.showToast("最多选择" + max + "个");
                    }
                }
                ((LiuhecaiMainAdapter) gridView.getAdapter()).notifyDataSetChanged();

                getMoney();
            }
        });
    }

    private void itemClicks(final GridView gridView, final int position) {
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) {
                liuheItems.get(position).get(j).choose = !liuheItems.get(position).get(j).choose;
                ((LiuhecaiMainAdapter) gridView.getAdapter()).notifyDataSetChanged();

                getMoney();
            }
        });
    }

    private void getMoney() {
        switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
            case "zhengmaguoguan": {
                int sum = 0;
                for (ArrayList<LiuheBean> liuheBeens : liuheItems) {
                    for (LiuheBean liuheBean : liuheBeens) {
                        if (liuheBean.choose) {
                            sum++;
                        }
                    }
                }

                if (sum > 1) {
                    int my;
                    if (!mBottomOrderLayout.getMoney_and_num().getText().toString().equals("")) {
                        my = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                    } else {
                        my = 0;
                    }
                    mBottomOrderLayout.getNumAndMoney().setText(sum + "串1    " + my + "元");
                    totalMoneys = my;

                    mBottomOrderLayout.bottomShowState2();
                } else {
                    mBottomOrderLayout.bottomShowState1();
                }
                break;
            }
            case "zixuanbuzhong":
            case "lianxiao":
            case "lianma":
            case "lianwei":
            case "zhongyi":
                int index = -1;
                totalNum = 0;
                totalNums = new int[liuheItems.size()];
                for (ArrayList<LiuheBean> list : liuheItems) {
                    index++;
                    int sum = 0;
                    for (LiuheBean liuheBean : list) {
                        if (liuheBean.choose) {
                            sum++;
                        }
                    }
                    final int t = sum;
                    final int m = index;
                    String func = "javascript:number_combinations_forLHC(" + t + "," + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(m).getNeed_number() + "," + m + ")";
                    webView.loadUrl(func);
                }
                break;
            default: {
                int sum = 0;
                for (ArrayList<LiuheBean> liuheBeens : liuheItems) {
                    for (LiuheBean liuheBean : liuheBeens) {
                        if (liuheBean.choose) {
                            sum++;
                        }
                    }
                }
                if (sum == 0) {
                    mBottomOrderLayout.bottomShowState1();
                } else {
                    int my;
                    if (!mBottomOrderLayout.getMoney_and_num().getText().toString().equals("")) {
                        my = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                    } else {
                        my = 0;
                    }
                    mBottomOrderLayout.getNumAndMoney().setText(sum + "注" + my * sum + "元");
                    totalMoneys = my * sum;

                    mBottomOrderLayout.bottomShowState2();
                }
                break;
            }
        }
    }

    public void setDatas() {
        setDatas(false);
    }

    /**
     * @param random_bet 是否是随机一注的逻辑
     */
    public void setDatas(boolean random_bet) {
        myAdapters.clear();
        myGridViews.clear();
        oddTotal.setVisibility(View.GONE);
        if (getLotteryDetailResponse != null) {
            method_name.setText(getLotteryDetailResponse.getLayouts().get(mIndex).getName());

            switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
                case "temaab": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_FIXED);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    ArrayList<Integer> indexes = new ArrayList<>();
                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getIs_last() != null) {
                            if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getIs_last().equals("0")) {
                                indexes.add(i);
                            }
                        }
                    }

                    for (int i = 0; i < indexes.size() + 1; i++) {
                        if (i == indexes.size()) {//其它
                            ArrayList<LiuheBean> liuheBeens = new ArrayList<>();

                            for (int j = 0; j < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); j++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getIs_last() != null) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getIs_last().equals("1")) {
                                        LiuheBean liuheBean = new LiuheBean();
                                        liuheBean.number = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getName();
                                        for (Object key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().keySet()) {
                                            if (liuheBean.odd == null) {
                                                liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().get(key).toString();
                                            } else {
                                                liuheBean.odd = liuheBean.odd + "," + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().get(key).toString();
                                            }
                                        }
                                        liuheBean.name = "其它";
                                        liuheBean.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getRule_id();
                                        liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_rakeback();
                                        liuheBeens.add(liuheBean);
                                    }
                                }
                            }
                            liuheItems.add(liuheBeens);

                            View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                            mViewList.add(view);

                            GridView gridView = view.findViewById(R.id.grid_view);
                            gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 12));
                            gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 17));
                            gridView.setNumColumns(5);
                            LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 2, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);

                            myAdapters.add(myAdapter);
                            myGridViews.add(gridView);

                            itemClicks(gridView, i);
                        } else {//特码A和特码
                            ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                            ArrayList<String> keys = new ArrayList<>(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getMax_odds().keySet());
                            for (String key : keys) {
                                LiuheBean liuheBean = new LiuheBean();
                                liuheBean.number = key;
                                liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getMax_odds().get(key).toString();
                                liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getMax_rakeback();
                                liuheBean.name = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getName();
                                liuheBean.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getRule_id();
                                liuheBeens.add(liuheBean);
                            }
                            liuheItems.add(liuheBeens);

                            View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                            mViewList.add(view);

                            View view1 = view.findViewById(R.id.tips);
                            view1.setVisibility(View.GONE);

                            GridView gridView = view.findViewById(R.id.grid_view);
                            final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 1, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);

                            myAdapters.add(myAdapter);
                            myGridViews.add(gridView);

                            itemClicks(gridView, i);

                            LHCLeftMenuView tema_list = view.findViewById(R.id.tema_list);
                            tema_list.setOnLHCLeftClickListener(onLHCLeftClickListener);
                            tema_list.setVisibility(View.VISIBLE);
                            view.findViewById(R.id.v_divider).setVisibility(View.VISIBLE);
                        }
                    }

                    MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
                    viewPager.setAdapter(mAdapter);
                    tabs.setupWithViewPager(viewPager);
                    tabs.setTabMode(TabLayout.MODE_FIXED);

                    for (int i = 0; i < tabs.getTabCount(); i++) {
                        TabLayout.Tab tab = tabs.getTabAt(i);
                        View view1 = LayoutInflater.from(LiuhecaiDetailActivity.this).inflate(R.layout.custom_tab_liuhe, null);
                        View view2 = view1.findViewById(R.id.imageView);
                        view1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                        TextView name = view1.findViewById(R.id.name);
                        if (i != 0) {
                            view2.setVisibility(View.GONE);
                            name.setTextColor(Color.parseColor("#3f3f3f"));
                        } else {
                            view2.setVisibility(View.VISIBLE);
                            name.setTextColor(getResources().getColor(R.color.purples));
                        }
                        if (i == indexes.size()) {
                            name.setText("其它");
                        } else {
                            name.setText(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getName());
                            if (!random_bet) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getSelected() != null) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getSelected().equals("1")) {
                                        if (indexes.get(i) < tabs.getTabCount()) {
                                            whichTabNo = indexes.get(i);
                                        }
                                    }
                                }
                            }
                        }

                        tab.setCustomView(view1);
                    }

                    setTabs();

                    viewPager.setCurrentItem(whichTabNo);
                    break;
                }
                case "liangmian": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    ArrayList<Integer> indexes = new ArrayList<>();
                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getIs_last() != null) {
                            if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getIs_last().equals("0")) {
                                indexes.add(i);
                            }
                        }
                    }

                    for (int i = 0; i < indexes.size() + 1; i++) {
                        if (i == indexes.size()) {
                            ArrayList<LiuheBean> liuheBeens = new ArrayList<>();

                            for (int j = 0; j < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); j++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getIs_last() != null) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getIs_last().equals("1")) {
                                        LiuheBean liuheBean = new LiuheBean();
                                        liuheBean.number = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getName();
                                        for (Object key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().keySet()) {
                                            if (liuheBean.odd == null) {
                                                liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().get(key).toString();
                                            } else {
                                                liuheBean.odd = liuheBean.odd + "," + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_odds().get(key).toString();
                                            }
                                        }
                                        liuheBean.name = "其他";
                                        liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getMax_rakeback();
                                        liuheBean.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(j).getRule_id();
                                        liuheBeens.add(liuheBean);
                                    }
                                }
                            }
                            liuheItems.add(liuheBeens);

                            View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                            mViewList.add(view);

                            View view1 = view.findViewById(R.id.tips);
                            view1.setVisibility(View.GONE);

                            GridView gridView = view.findViewById(R.id.grid_view);
                            gridView.setNumColumns(5);
                            gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 12));
                            gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 17));
                            LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 2, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);
                            myAdapters.add(myAdapter);

                            itemClicks(gridView, i);
                        } else {
                            ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                            for (GetLotteryDetailResponse.LayoutsBean.ChildrenBeanX.ChildrenBean childrenBean : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getChildren()) {
                                LiuheBean liuheBean = new LiuheBean();
                                liuheBean.number = childrenBean.getName();
                                liuheBean.rule_id = childrenBean.getRule_id();
                                for (Object key : childrenBean.getMax_odds().keySet()) {
                                    if (liuheBean.odd == null) {
                                        liuheBean.odd = childrenBean.getMax_odds().get(key).toString();
                                    } else {
                                        liuheBean.odd = liuheBean.odd + "," + childrenBean.getMax_odds().get(key).toString();
                                    }
                                }
                                liuheBean.name = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getName();
                                liuheBean.rakeback = childrenBean.getMax_rakeback();
                                liuheBeens.add(liuheBean);
                            }
                            liuheItems.add(liuheBeens);

                            View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                            mViewList.add(view);

                            View view1 = view.findViewById(R.id.tips);
                            view1.setVisibility(View.GONE);

                            GridView gridView = view.findViewById(R.id.grid_view);
                            gridView.setNumColumns(5);
                            gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 12));
                            gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 17));
                            LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 2, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);
                            myAdapters.add(myAdapter);

                            itemClicks(gridView, i);
                        }
                    }

                    MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
                    viewPager.setAdapter(mAdapter);
                    tabs.setupWithViewPager(viewPager);

                    for (int i = 0; i < tabs.getTabCount(); i++) {
                        TabLayout.Tab tab = tabs.getTabAt(i);
                        View view1 = LayoutInflater.from(LiuhecaiDetailActivity.this).inflate(R.layout.custom_tab_liuhe, null);
                        View view2 = view1.findViewById(R.id.imageView);
                        view1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                        TextView name = view1.findViewById(R.id.name);
                        if (i != 0) {
                            view2.setVisibility(View.GONE);
                            name.setTextColor(Color.parseColor("#3f3f3f"));
                        } else {
                            view2.setVisibility(View.VISIBLE);
                            name.setTextColor(getResources().getColor(R.color.purples));
                        }
                        if (i == indexes.size()) {
                            name.setText("其它");
                        } else {
                            name.setText(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(indexes.get(i)).getName());
                        }

                        tab.setCustomView(view1);
                    }

                    setTabs();

                    viewPager.setCurrentItem(whichTabNo);
                    break;
                }
                case "zhengma": {
                    tabs.setVisibility(View.GONE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                    ArrayList<String> keys = new ArrayList<>(getLotteryDetailResponse.getLayouts().get(mIndex).getMax_odds().keySet());
                    for (String key : keys) {
                        LiuheBean liuheBean = new LiuheBean();
                        liuheBean.number = key;
                        liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getMax_odds().get(key).toString();
                        liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getMax_rakeback();
                        liuheBeens.add(liuheBean);
                    }
                    liuheItems.add(liuheBeens);

                    View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                    mViewList.add(view);

                    View view1 = view.findViewById(R.id.tips);
                    view1.setVisibility(View.GONE);

                    GridView gridView = view.findViewById(R.id.grid_view);
                    gridView.setNumColumns(6);
                    final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(0), 1, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                    gridView.setAdapter(myAdapter);
                    myAdapters.add(myAdapter);
                    myGridViews.add(gridView);

                    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) {
                            liuheItems.get(0).get(j).choose = !liuheItems.get(0).get(j).choose;
                            myAdapter.notifyDataSetChanged();

                            getMoney();
                        }
                    });

                    MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
                    viewPager.setAdapter(mAdapter);
                    viewPager.setCurrentItem(whichTabNo);

                    LHCLeftMenuView tema_list = view.findViewById(R.id.tema_list);
                    tema_list.setOnLHCLeftClickListener(onLHCLeftClickListener);
                    tema_list.setVisibility(View.VISIBLE);
                    view.findViewById(R.id.v_divider).setVisibility(View.VISIBLE);
                    break;
                }
                case "zhengmate":
                case "lianma": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        ArrayList<String> keys = new ArrayList<>(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().keySet());
                        if ("lianma".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            StringBuilder odds = null;
                            for (String key : keys) {
                                if (odds == null) {
                                    odds = new StringBuilder(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString());
                                } else {
                                    odds.append(",").append(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString());
                                }
                            }

                            for (int s = 1; s <= 49; s++) {
                                String a = s + "";
                                if (s < 10) {
                                    a = String.format("%02d", s);
                                }
                                LiuheBean liuheBean = new LiuheBean();
                                liuheBean.number = a;
                                liuheBean.odd = odds.toString();
                                liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_rakeback();
                                liuheBeens.add(liuheBean);
                            }
                        } else {
                            for (String key : keys) {
                                LiuheBean liuheBean = new LiuheBean();
                                liuheBean.number = key;
                                liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString();
                                liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_rakeback();
                                liuheBeens.add(liuheBean);
                            }
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);

                        View view1 = view.findViewById(R.id.tips);
                        view1.setVisibility(View.GONE);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 1, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                        gridView.setAdapter(myAdapter);
                        myAdapters.add(myAdapter);
                        myGridViews.add(gridView);

                        if ("lianma".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            itemClicks(gridView, i, 10);
                        } else {
                            itemClicks(gridView, i);
                        }

                        LHCLeftMenuView tema_list = view.findViewById(R.id.tema_list);
                        tema_list.setOnLHCLeftClickListener(onLHCLeftClickListener);
                        tema_list.setVisibility(View.VISIBLE);
                        view.findViewById(R.id.v_divider).setVisibility(View.VISIBLE);
                    }

                    setViewPagerState(mViewList);
                    break;
                }
                case "zhengma16": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        for (GetLotteryDetailResponse.LayoutsBean.ChildrenBeanX.ChildrenBean childrenBean : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getChildren()) {
                            LiuheBean liuheBean = new LiuheBean();
                            liuheBean.number = childrenBean.getName();
                            for (Object key : childrenBean.getMax_odds().keySet()) {
                                if (liuheBean.odd == null) {
                                    liuheBean.odd = childrenBean.getMax_odds().get(key).toString();
                                } else {
                                    liuheBean.odd = liuheBean.odd + "," + childrenBean.getMax_odds().get(key).toString();
                                }
                            }
                            liuheBean.rule_id = childrenBean.getRule_id();
                            liuheBean.rakeback = childrenBean.getMax_rakeback();
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        gridView.setNumColumns(5);
                        gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 12));
                        gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 17));
                        final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 2, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                        gridView.setAdapter(myAdapter);
                        myAdapters.add(myAdapter);

                        itemClicks(gridView, i);
                    }

                    setViewPagerState(mViewList);
                    break;
                }
                case "zhengmaguoguan": {
                    tabs.setVisibility(View.GONE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getOdds().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        for (GetLotteryDetailResponse.LayoutsBean.OddsBean oddsBean : getLotteryDetailResponse.getLayouts().get(mIndex).getOdds().get(i)) {
                            LiuheBean liuheBean = new LiuheBean();
                            liuheBean.number = oddsBean.getNameX();
                            liuheBean.odd = oddsBean.getOdds();
                            liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getMax_rakeback();
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);
                    }

                    View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe2, null);
                    mViewList.add(view);

                    zhengmaguoguanListView = view.findViewById(R.id.listview);
                    zhengmaguoguanAdapter = new LiuhecaiDetailListView(liuheItems, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                    zhengmaguoguanAdapter.setLiuhecaiDetailListWatch(new LiuhecaiDetailListWatch() {
                        @Override
                        public void clickWatch(int j, int position) {
                            //只能选一个
                            if (liuheItems.get(position).get(j).choose) {
                                liuheItems.get(position).get(j).choose = false;
                            } else {
                                for (LiuheBean bean : liuheItems.get(position)) {
                                    bean.choose = false;
                                }
                                liuheItems.get(position).get(j).choose = true;
                            }
                            zhengmaguoguanAdapter.notifyDataSetChanged();

                            getMoney();
                        }
                    });
                    zhengmaguoguanListView.setAdapter(zhengmaguoguanAdapter);


                    MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
                    viewPager.setAdapter(mAdapter);
                    viewPager.setCurrentItem(whichTabNo);
                    break;
                }
                case "lianxiao":
                case "lianwei": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_FIXED);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        ArrayList<String> keys = new ArrayList<>(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().keySet());
                        for (String key : keys) {
                            LiuheBean liuheBean = new LiuheBean();

                            liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString();
                            liuheBean.minOdd = Float.parseFloat(liuheBean.odd);

                            liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_rakeback();
                            if ("lianxiao".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                liuheBean.number = key;
                                for (LinkedHashMap.Entry<String, String> e : getLotteryDetailResponse.getSx().entrySet()) {
                                    if (e.getValue().equals(key)) {
                                        if (liuheBean.nums == null) {
                                            liuheBean.nums = e.getKey();
                                        } else {
                                            liuheBean.nums = liuheBean.nums + " " + e.getKey();
                                        }
                                    }
                                }
                            } else if ("lianwei".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                liuheBean.number = "尾" + key;

                                int length = 49;
                                int times = length / 10 + (Integer.parseInt(key) % 10 == 0 ? 0 : 1);
                                for (int k = 0; k < times; k++) {
                                    if (key.equals("0")) {
                                        if (liuheBean.nums == null) {
                                            liuheBean.nums = String.format("%02d", Integer.parseInt(key) + (k + 1) * 10);
                                        } else {
                                            liuheBean.nums = liuheBean.nums + " " + String.format("%02d", Integer.parseInt(key) + (k + 1) * 10);
                                        }
                                    } else {
                                        if (liuheBean.nums == null) {
                                            liuheBean.nums = String.format("%02d", Integer.parseInt(key) + k * 10);
                                        } else {
                                            liuheBean.nums = liuheBean.nums + " " + String.format("%02d", Integer.parseInt(key) + k * 10);
                                        }
                                    }
                                }
                            }
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        gridView.setNumColumns(3);
                        gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 10));
                        gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 15));
                        if ("lianwei".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 6, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);
                            myAdapters.add(myAdapter);
                        } else {
                            LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 3, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                            gridView.setAdapter(myAdapter);
                            myAdapters.add(myAdapter);
                        }

                        itemClicks(gridView, i, 6);
                    }

                    setViewPagerState(mViewList);
                    break;
                }
                case "zixuanbuzhong":
                case "zhongyi": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    int[] zixuanbuzhongArray = new int[]{10, 10, 10, 11, 12, 13, 13, 14};
                    int[] zhongyiArray = new int[]{10, 10, 10, 11, 12, 13};

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        for (String key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getNums()) {
                            LiuheBean liuheBean = new LiuheBean();
                            liuheBean.number = key;
                            for (Object keys : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().keySet()) {
                                if (liuheBean.odd == null) {
                                    liuheBean.odd = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(keys).toString();
                                } else {
                                    liuheBean.odd = liuheBean.odd + "," + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(keys).toString();
                                }
                            }
                            liuheBean.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_rakeback();
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);

                        View view1 = view.findViewById(R.id.tips);
                        view1.setVisibility(View.GONE);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 4, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                        gridView.setAdapter(myAdapter);
                        myAdapters.add(myAdapter);
                        myGridViews.add(gridView);

                        LHCLeftMenuView tema_list = view.findViewById(R.id.tema_list);
                        tema_list.setOnLHCLeftClickListener(onLHCLeftClickListener);
                        tema_list.setVisibility(View.VISIBLE);
                        view.findViewById(R.id.v_divider).setVisibility(View.VISIBLE);
                        if ("zixuanbuzhong".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            itemClicks(gridView, i, zixuanbuzhongArray[i]);
                        } else if ("zhongyi".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            itemClicks(gridView, i, zhongyiArray[i]);
                        }
                    }

                    MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
                    viewPager.setAdapter(mAdapter);
                    tabs.setupWithViewPager(viewPager);

                    for (int i = 0; i < tabs.getTabCount(); i++) {
                        TabLayout.Tab tab = tabs.getTabAt(i);
                        View view1 = LayoutInflater.from(LiuhecaiDetailActivity.this).inflate(R.layout.custom_tab_liuhe, null);
                        view1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                        View view2 = view1.findViewById(R.id.imageView);
                        TextView name = view1.findViewById(R.id.name);
                        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) name.getLayoutParams();
                        layoutParams.topMargin = Utils.dip2px(LiuhecaiDetailActivity.this, 5);
                        name.setLayoutParams(layoutParams);
                        if (i != 0) {
                            view2.setVisibility(View.GONE);
                            name.setTextColor(getResources().getColor(R.color.lottery_black));
                        } else {
                            view2.setVisibility(View.VISIBLE);
                            name.setTextColor(getResources().getColor(R.color.purples));
                        }
                        name.setText(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName());
                        TextView odd = view1.findViewById(R.id.odd);
                        odd.setVisibility(View.VISIBLE);
                        StringBuilder oddString = null;
                        for (Object key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().keySet()) {
                            if (oddString == null) {
                                oddString = new StringBuilder(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString());
                            } else {
                                oddString.append(",").append(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key).toString());
                            }
                        }
                        odd.setText(oddString.toString());

                        tab.setCustomView(view1);
                    }

                    setTabs();
                    viewPager.setCurrentItem(whichTabNo);
                    break;
                }
                case "shengxiao":
                case "sebo":
                case "touweishu":
                case "qimawuxing": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_FIXED);

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        for (GetLotteryDetailResponse.LayoutsBean.ChildrenBeanX.ChildrenBean key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getChildren()) {
                            LiuheBean liuheBean = new LiuheBean();
                            for (Object keys : key.getMax_odds().keySet()) {
                                if (liuheBean.odd == null) {
                                    liuheBean.odd = key.getMax_odds().get(keys).toString();
                                } else {
                                    liuheBean.odd = liuheBean.odd + "," + key.getMax_odds().get(keys).toString();
                                }
                            }
                            liuheBean.rakeback = key.getMax_rakeback();
                            liuheBean.number = key.getName();
                            if (key.getSx() != null) {
                                liuheBean.nums = key.getSx();
                            }
                            if (key.getName().startsWith("红")) {
                                liuheBean.color = Color.parseColor("#cf5b5b");
                            } else if (key.getName().startsWith("蓝")) {
                                liuheBean.color = Color.parseColor("#5773c2");
                            } else if (key.getName().startsWith("绿")) {
                                liuheBean.color = Color.parseColor("#7eb379");
                            } else if (key.getName().equals("和局")) {//和局是特殊情况
                                liuheBean.color = Color.parseColor("#cf5b5b");
                            }
                            liuheBean.rule_id = key.getRule_id();
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        gridView.setNumColumns(3);
                        gridView.setHorizontalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 10));
                        gridView.setVerticalSpacing(Utils.dip2px(LiuhecaiDetailActivity.this, 6));
                        int type = 5;
                        if ("shengxiao".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                            if (!getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("总肖")) {//总肖 是特殊情况
                                type = 3;
                            }
                        }
                        LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), type, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                        gridView.setAdapter(myAdapter);
                        myAdapters.add(myAdapter);

                        itemClicks(gridView, i);
                    }

                    setViewPagerState(mViewList);
                    break;
                }
                case "hexiao": {
                    tabs.setVisibility(View.VISIBLE);
                    tabs.setTabMode(TabLayout.MODE_FIXED);
                    oddTotal.setVisibility(View.VISIBLE);
                    oddTotal.setText("赔率:" + "0.0");

                    liuheItems = new ArrayList();

                    ArrayList<View> mViewList = new ArrayList<>();

                    hexiaoOdds = new float[getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size()];

                    for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                        ArrayList<LiuheBean> liuheBeens = new ArrayList<>();
                        for (GetLotteryDetailResponse.LayoutsBean.ChildrenBeanX.ChildrenBean key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getItems()) {
                            LiuheBean liuheBean = new LiuheBean();
                            liuheBean.number = key.getName();
                            liuheBean.nums = key.getSx();
                            liuheBean.hexiaoNumber = Float.parseFloat(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getMax_odds().get(key.getName()).toString());
                            liuheBean.odd = liuheBean.hexiaoNumber + "";
                            liuheBeens.add(liuheBean);
                        }
                        liuheItems.add(liuheBeens);

                        View view = getLayoutInflater().inflate(R.layout.custom_tab_liuhe1, null);
                        mViewList.add(view);
                        View view1 = view.findViewById(R.id.hexiao_divider);
                        view1.setVisibility(View.VISIBLE);

                        GridView gridView = view.findViewById(R.id.grid_view);
                        gridView.setNumColumns(3);
                        final LiuhecaiMainAdapter myAdapter = new LiuhecaiMainAdapter(liuheItems.get(i), 3, LiuhecaiDetailActivity.this, getLotteryDetailResponse);
                        gridView.setAdapter(myAdapter);
                        myAdapters.add(myAdapter);

                        final ArrayList<QuickChoose> tabKeys = new ArrayList<>();
                        for (String key : getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getTabs().keySet()) {
                            QuickChoose quickChoose = new QuickChoose();
                            quickChoose.setKey(key);
                            tabKeys.add(quickChoose);
                        }

                        NoScrollGridView noScrollGridView = view.findViewById(R.id.quick_choose);
                        noScrollGridView.setVisibility(View.VISIBLE);
                        final HexiaoAdapterAdapter adapter2 = new HexiaoAdapterAdapter(tabKeys, LiuhecaiDetailActivity.this);
                        noScrollGridView.setAdapter(adapter2);

                        final int position = i;
                        noScrollGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int m, long l) {//满11不能再继续选择了
                                boolean isChoose = false;//是否有选中的状态
                                for (QuickChoose quickChoose : tabKeys) {
                                    if (tabKeys.get(m).getKey().equals(quickChoose.getKey())) {
                                        if (quickChoose.isChoose()) {
                                            quickChoose.setChoose(false);
                                        } else {
                                            quickChoose.setChoose(true);
                                            isChoose = true;
                                        }
                                    } else {
                                        quickChoose.setChoose(false);
                                    }
                                }
                                adapter2.notifyDataSetChanged();

                                int sum = 0;
                                List<String> list = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(position).getTabs().get(tabKeys.get(m).getKey());
                                float sumOdds = 0;
                                float sumOddsNo = 0;//不中
                                for (LiuheBean liuheBean : liuheItems.get(position)) {
                                    if (isChoose) {
                                        if (list.contains(liuheBean.number)) {
                                            liuheBean.choose = true;
                                            sumOdds += liuheBean.hexiaoNumber;
                                            sum++;
                                        } else {
                                            liuheBean.choose = false;
                                            sumOddsNo += liuheBean.hexiaoNumber;
                                        }
                                    } else {
                                        liuheBean.choose = false;
                                    }
                                }
                                myAdapter.notifyDataSetChanged();

                                if (sum != 0) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(position).getLayout_code().equals("hexiao_zhong")) {
                                        hexiaoOdds[position] = sumOdds / sum / sum;
                                        BigDecimal b = new BigDecimal(hexiaoOdds[position]);
                                        hexiaoOdds[position] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                    } else {
                                        hexiaoOdds[position] = sumOddsNo / (12 - sum) / (12 - sum);
                                        BigDecimal b = new BigDecimal(hexiaoOdds[position]);
                                        hexiaoOdds[position] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                    }
                                } else {
                                    hexiaoOdds[position] = 0;

                                    oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                }

                                setHexiaoMoney();
                            }
                        });

                        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) {//满11不能再继续选择了
                                int sum = 0;
                                if (liuheItems.get(position).get(j).choose) {
                                    liuheItems.get(position).get(j).choose = false;
                                } else {
                                    int s = 0;
                                    for (LiuheBean liuheBean : liuheItems.get(position)) {
                                        if (liuheBean.choose) {
                                            s++;
                                        }
                                    }
                                    if (s >= 10) {
                                        Utils.showToast("最多只能选择10个");
                                        return;
                                    }

                                    liuheItems.get(position).get(j).choose = true;
                                }
                                myAdapter.notifyDataSetChanged();

                                for (QuickChoose quickChoose : tabKeys) {
                                    quickChoose.setChoose(false);
                                }
                                adapter2.notifyDataSetChanged();

                                float sumOdds = 0;
                                float sumOddsNo = 0;
                                for (LiuheBean liuheBean : liuheItems.get(position)) {
                                    if (liuheBean.choose) {
                                        sum++;
                                        sumOdds += liuheBean.hexiaoNumber;
                                    } else {
                                        sumOddsNo += liuheBean.hexiaoNumber;
                                    }
                                }

                                if (sum != 0) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(position).getLayout_code().equals("hexiao_zhong")) {
                                        hexiaoOdds[position] = sumOdds / sum / sum;
                                        BigDecimal b = new BigDecimal(hexiaoOdds[position]);
                                        hexiaoOdds[position] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                    } else {
                                        hexiaoOdds[position] = sumOddsNo / (12 - sum) / (12 - sum);
                                        BigDecimal b = new BigDecimal(hexiaoOdds[position]);
                                        hexiaoOdds[position] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                    }
                                } else {
                                    hexiaoOdds[position] = 0;

                                    oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                                }

                                setHexiaoMoney();
                            }
                        });
                    }

                    setViewPagerState(mViewList);
                    break;
                }
            }
        }

        getMoney();
    }

    private void setHexiaoMoney() {
        int sums = 0;
        for (ArrayList<LiuheBean> liuheBeans : liuheItems) {
            for (LiuheBean liuheBean : liuheBeans) {
                if (liuheBean.choose) {
                    sums++;
                    break;
                }
            }
        }
        if (sums == 0) {
            mBottomOrderLayout.bottomShowState1();
        } else {
            mBottomOrderLayout.bottomShowState2();
            int my;
            if (!mBottomOrderLayout.getMoney_and_num().getText().toString().equals("")) {
                my = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
            } else {
                my = 0;
            }
            mBottomOrderLayout.getNumAndMoney().setText(sums + "种组合   " + my * sums + "元");
            totalMoneys = my * sums;
        }
    }

    private void setViewPagerState(ArrayList<View> mViewList) {
        MyPagerAdapter mAdapter = new MyPagerAdapter(mViewList);
        viewPager.setAdapter(mAdapter);
        tabs.setupWithViewPager(viewPager);

        for (int i = 0; i < tabs.getTabCount(); i++) {
            TabLayout.Tab tab = tabs.getTabAt(i);
            View view1 = LayoutInflater.from(LiuhecaiDetailActivity.this).inflate(R.layout.custom_tab_liuhe, null);
            view1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            TextView name = view1.findViewById(R.id.name);
            View view2 = view1.findViewById(R.id.imageView);
            if (i != 0) {
                view2.setVisibility(View.GONE);
                name.setTextColor(Color.parseColor("#3f3f3f"));
            } else {
                view2.setVisibility(View.VISIBLE);
                name.setTextColor(getResources().getColor(R.color.purples));
            }
            name.setText(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName());

            tab.setCustomView(view1);
        }

        setTabs();
        viewPager.setCurrentItem(whichTabNo);
    }

    private void setTabs() {
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                whichTabNo = position;
                for (int i = 0; i < tabs.getTabCount(); i++) {
                    if (i == position) {
                        tabs.getTabAt(i).getCustomView().findViewById(R.id.imageView).setVisibility(View.VISIBLE);

                        if (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code().equals("hexiao") && hexiaoOdds != null) {//专门针对合肖的处理
                            if (position + 1 <= hexiaoOdds.length) {
                                oddTotal.setText("赔率:" + hexiaoOdds[position] + "");
                            }
                        }
                        ((TextView) (tabs.getTabAt(i).getCustomView().findViewById(R.id.name))).setTextColor(getResources().getColor(R.color.purples));
                    } else {
                        tabs.getTabAt(i).getCustomView().findViewById(R.id.imageView).setVisibility(View.GONE);

                        ((TextView) (tabs.getTabAt(i).getCustomView().findViewById(R.id.name))).setTextColor(Color.parseColor("#3f3f3f"));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    public void gotoOrderList() {
        //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_betrecord_jump");

        if (!UserInfo.getToken().equals("")) {
            startActivity(new Intent(this, OrderActivity.class));//切换到第四个tab栏
        } else {
            gotoLoginActivity();
        }
    }

    public void gotoPrizeList() {
        //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_numdistributing_jump");

        Intent intent = new Intent(this, LiuhecaiPrizeActivity.class);
        intent.putExtra("code", getIntent().getStringExtra("code"));
        startActivity(intent);
    }

    public void recentPrize() {
        if (container.getVisibility() == View.VISIBLE || animPrize.getVisibility() == View.VISIBLE) {
            container.setVisibility(View.GONE);
            animPrize.setVisibility(View.GONE);
            shadow.setVisibility(View.GONE);
            animPrize.pauseAnimation();

            prizeList.setVisibility(View.VISIBLE);
            animView.setAnimation("xia.json");
            animView.playAnimation();
        } else {
            shadow.setVisibility(View.GONE);
            if (mIsPrizeTime) {
                animPrize.setVisibility(View.VISIBLE);
                animPrize.resumeAnimation();
            } else {
                container.setVisibility(View.VISIBLE);
            }
            prizeList.setVisibility(View.GONE);
            animView.setAnimation("shang.json");
            animView.playAnimation();
        }
    }

    public void gotoRule() {
        //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_lotteryrule_jump");

        Intent intent = new Intent(this, PlayRuleActivity.class);
        intent.putExtra("code", getIntent().getStringExtra("code"));
        startActivity(intent);
    }

    public void gotoPlayTip() {
        //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_playmethod_jump");

        Intent intent = new Intent(this, PlayTipActivity.class);
        intent.putExtra("tips", getLotteryDetailResponse.getLayouts().get(mIndex).getTips());
        startActivity(intent);
    }

    private void createOneBet() {
        setDatas(true);
        Gson gson = new Gson();
        String zmgg_rule_id = "0";
        String rakeback = "0";
        String func = "";
        switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
            case "zhengmaguoguan":
                zmgg_rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getRule_id();
                rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getMax_rakeback();
                String s = zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getOdds());
                func = "javascript:generate_item_lhcs(" + s + ")";
                break;
            case "liangmian":
                if (whichTabNo == 6) {//共7个tab栏
                    String s2 = zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren());
                    func = "javascript:generate_item_lhcs(" + s2 + ")";
                } else {
                    switch (whichTabNo) {
                        case 0: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码一")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                        case 1: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码二")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                        case 2: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码三")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                        case 3: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码四")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                        case 4: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码五")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                        case 5: {
                            int index = 0;
                            for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                                if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("正码六")) {
                                    index = i;
                                    break;
                                }
                            }
                            func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getChildren()) + ")";
                            break;
                        }
                    }
                }
                break;
            case "temaab":
                switch (whichTabNo) {
                    case 2:
                        func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren()) + ")";
                        break;
                    case 0: {
                        int index = 0;
                        for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                            if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("特码A")) {
                                index = i;
                                break;
                            }
                        }
                        func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index)) + ")";
                        break;
                    }
                    case 1: {
                        int index = 0;
                        for (int i = 0; i < getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().size(); i++) {
                            if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(i).getName().equals("特码B")) {
                                index = i;
                                break;
                            }
                        }
                        func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index)) + ")";
                        break;
                    }
                }
                break;
            case "zhengma":
                func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex)) + ")";
                break;
            case "zhengmate":
            case "lianma":
            case "lianxiao":
            case "lianwei":
            case "zixuanbuzhong":
            case "hexiao":
            case "zhongyi":
                func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(whichTabNo)) + ")";
                break;
            case "zhengma16":
            case "shengxiao":
            case "sebo":
            case "touweishu":
            case "qimawuxing":
                func = "javascript:generate_item_lhcs(" + zmgg_rule_id + "," + rakeback + "," + 1 + "," + gson.toJson(getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(whichTabNo).getChildren()) + ")";
                break;
        }

        webviewRandom.loadUrl(func);
    }

    @JavascriptInterface
    public void getRandomString(final String notes) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {//手写没有逗号隔开，选择则是逗号
                try {
                    JSONObject jsonObject = new JSONObject(notes);
                    switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
                        case "zhengmaguoguan":
                            String[] pick_number = jsonObject.getString("pick_number").split(",");
                            String[] position = jsonObject.getString("position").split(",");
                            for (int i = 0; i < pick_number.length; i++) {
                                liuheItems.get(Integer.parseInt(pick_number[i])).get(Integer.parseInt(position[i])).choose = true;
                            }
                            if (zhengmaguoguanListView != null) {
                                zhengmaguoguanListView.setSelection(0);
                            }
                            zhengmaguoguanAdapter.notifyDataSetChanged();
                            break;
                        case "liangmian":
                        case "temaab":
                        case "zhengmate":
                        case "zhengma16":
                        case "lianma":
                        case "lianxiao":
                        case "lianwei":
                        case "zixuanbuzhong":
                        case "zhongyi":
                        case "shengxiao":
                        case "sebo":
                        case "touweishu":
                        case "qimawuxing":
                        case "hexiao": {
                            int index = 0;
                            String[] p = jsonObject.getString("pick_number").split(",");
                            int firstOne = 0;
                            int indexs = 0;
                            for (String r : p) {
                                for (int i = 0; i < liuheItems.get(whichTabNo).size(); i++) {
                                    if (liuheItems.get(whichTabNo).get(i).number.equals(r)) {
                                        index = i;
                                        if (firstOne == 0) {
                                            firstOne++;
                                            indexs = index;
                                        }
                                        break;
                                    }
                                }
                                liuheItems.get(whichTabNo).get(index).choose = true;
                            }
                            myAdapters.get(whichTabNo).notifyDataSetChanged();

                            //随机一注定位置
                            final int temp = indexs;
                            if ("temaab".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                    || "zhengmate".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                    || "lianma".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                    || "zixuanbuzhong".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                    || "zhongyi".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                    ) {
                                myGridViews.get(whichTabNo).post(new Runnable() {
                                    @Override
                                    public void run() {
                                        myGridViews.get(whichTabNo).setSelection(temp);
                                    }
                                });
                            }

                            if ("hexiao".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                int sum = 0;
                                float sumOdds = 0;
                                float sumOddsNo = 0;//不中
                                for (LiuheBean liuheBean : liuheItems.get(whichTabNo)) {
                                    if (liuheBean.choose) {
                                        sumOdds += liuheBean.hexiaoNumber;
                                        sum++;
                                    } else {
                                        sumOddsNo += liuheBean.hexiaoNumber;
                                    }
                                }

                                if (sum != 0) {
                                    if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(whichTabNo).getLayout_code().equals("hexiao_zhong")) {
                                        hexiaoOdds[whichTabNo] = sumOdds / sum / sum;
                                        BigDecimal b = new BigDecimal(hexiaoOdds[whichTabNo]);
                                        hexiaoOdds[whichTabNo] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[whichTabNo] + "");
                                    } else {
                                        hexiaoOdds[whichTabNo] = sumOddsNo / (12 - sum) / (12 - sum);
                                        BigDecimal b = new BigDecimal(hexiaoOdds[whichTabNo]);
                                        hexiaoOdds[whichTabNo] = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        oddTotal.setText("赔率:" + hexiaoOdds[whichTabNo] + "");
                                    }
                                } else {
                                    hexiaoOdds[whichTabNo] = 0;

                                    oddTotal.setText("赔率:" + hexiaoOdds[whichTabNo] + "");
                                }

                                setHexiaoMoney();

                                return;
                            }
                            break;
                        }
                        case "zhengma": {
                            int index = 0;
                            for (int i = 0; i < liuheItems.get(0).size(); i++) {
                                if (liuheItems.get(0).get(i).number.equals(jsonObject.getString("pick_number"))) {
                                    index = i;
                                    break;
                                }
                            }
                            liuheItems.get(0).get(index).choose = true;
                            myAdapters.get(0).notifyDataSetChanged();
                            final int pos = index;
                            myGridViews.get(0).post(new Runnable() {
                                @Override
                                public void run() {
                                    myGridViews.get(0).setSelection(pos);
                                }
                            });
                            break;
                        }
                    }
                    getMoney();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void confirmIfGotoShoppingCar(boolean gotoShoppingcar, ArrayList<LHCBetListActivity.Results> chooses) {
        if (gotoShoppingcar) {
            Intent intent = new Intent(this, LHCBetListActivity.class);
            intent.putExtra("colors", getLotteryDetailResponse.getColor());
            intent.putExtra("code", getIntent().getStringExtra("code"));
            intent.putParcelableArrayListExtra("lists", chooses);
            startActivity(intent);
        } else {
            setDatas(true);
            mBottomOrderLayout.bottomShowState1();
            LHCBetListActivity.liuheBeanArrayList.addAll(chooses);
        }
    }

    /**
     * 加入注单操作
     *
     * @param gotoShoppingcar true代表进入投注单界面，false代表只增加注单，不进入投注单界面
     */
    private void confirm(boolean gotoShoppingcar) {
        //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_buy");

        if (!UserInfo.getToken().equals("")) {
            if ((!downtime.getText().toString().startsWith("00:00:") && getIntent().getStringExtra("code").equals("xglhc")) || (!downtime.getText().toString().startsWith("00:00:0") && getIntent().getStringExtra("code").equals("jslhc"))|| (!downtime.getText().toString().startsWith("00:00:0") && getIntent().getStringExtra("code").equals("js10flhc"))) {//如果倒计时小于60秒，不能购买彩票。又加入了极速六合彩，提前十秒才可以买
                if (liuheItems != null && !mBottomOrderLayout.getMoney_and_num().getText().toString().equals("")) {
                    switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
                        case "hexiao":
                            int sums = 0;
                            for (ArrayList<LiuheBean> liuheBeans : liuheItems) {
                                for (LiuheBean liuheBean : liuheBeans) {
                                    if (liuheBean.choose) {
                                        sums++;
                                        break;
                                    }
                                }
                            }
                            if (sums > 0) {
//                                if (totalMoneys > Float.parseFloat(UserInfo.getAccount())) {
//                                    Utils.showToast("您的余额不足");
//                                } else {
                                    ArrayList<LHCBetListActivity.Results> chooses = new ArrayList<>();
                                    int index = 0;
                                    for (ArrayList<LiuheBean> liuheBeans : liuheItems) {
                                        StringBuilder number = null;
                                        int sum = 0;
                                        for (LiuheBean liuheBean : liuheBeans) {
                                            if (liuheBean.choose) {
                                                sum++;
                                                if (number == null) {
                                                    number = new StringBuilder(liuheBean.number);
                                                } else {
                                                    number.append(",").append(liuheBean.number);
                                                }
                                            }
                                        }
                                        if (sum > 0) {
                                            LHCBetListActivity.Results result = new LHCBetListActivity.Results();
                                            String tabString = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getName();
                                            result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + tabString + "-";
                                            result.single = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                                            result.odd = hexiaoOdds[index] + "";
                                            result.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getRule_id();
                                            result.number = number.toString();
                                            result.quantity = 1;
                                            result.total = result.single;
                                            result.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getMax_rakeback();
                                            chooses.add(result);
                                        }
                                        index++;
                                    }
                                    confirmIfGotoShoppingCar(gotoShoppingcar, chooses);
//                                }
                            } else {
                                Utils.showToast("请选择生肖");
                            }
                            break;
                        case "zhengmaguoguan":
                            int sum = 0;
                            float odds = 0f;
                            float result_odds = 0f;
                            StringBuilder number = null;
                            for (ArrayList<LiuheBean> liuheBeens : liuheItems) {
                                boolean exist = false;
                                for (LiuheBean liuheBean : liuheBeens) {
                                    if (liuheBean.choose) {
                                        sum++;
                                        if (odds == 0f) {
                                            odds = Float.parseFloat(liuheBean.odd);
                                            result_odds = Float.parseFloat(liuheBean.odd);
                                        } else {
                                            odds = (new BigDecimal(odds).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue()) * Float.parseFloat(liuheBean.odd);
                                            BigDecimal b = new BigDecimal(odds);
                                            result_odds = b.setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
                                        }

                                        if (number == null) {
                                            number = new StringBuilder(liuheBean.number);
                                        } else {
                                            number.append(",").append(liuheBean.number);
                                        }
                                        exist = true;
                                        break;
                                    }
                                }
                                if (!exist) {
                                    if (number == null) {
                                        number = new StringBuilder("");
                                    } else {
                                        number.append("," + "");
                                    }
                                }
                            }

                            if (sum > 1) {
//                                if (totalMoneys > Float.parseFloat(UserInfo.getAccount())) {
//                                    Utils.showToast("您的余额不足");
//                                } else {
                                    ArrayList<LHCBetListActivity.Results> chooses = new ArrayList<>();
                                    LHCBetListActivity.Results result = new LHCBetListActivity.Results();
                                    result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + "-" + sum + "串1";
                                    result.single = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                                    result.odd = result_odds + "";
                                    result.rakeback = getLotteryDetailResponse.getLayouts().get(mIndex).getMax_rakeback();
                                    result.number = number.toString();
                                    result.total = result.single;
                                    result.quantity = 1;
                                    result.total = result.single * result.quantity;
                                    result.type = getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code();
                                    result.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getRule_id();
                                    chooses.add(result);

                                    confirmIfGotoShoppingCar(gotoShoppingcar, chooses);
//                                }
                            } else {
                                Utils.showToast("至少选择两个球");
                            }
                            break;
                        case "zixuanbuzhong":
                        case "lianxiao":
                        case "lianma":
                        case "lianwei":
                        case "zhongyi":
                            if (totalNum > 0) {
//                                if (totalMoneys > Float.parseFloat(UserInfo.getAccount())) {
//                                    Utils.showToast("您的余额不足");
//                                } else {
                                    ArrayList<LHCBetListActivity.Results> chooses = new ArrayList<>();
                                    int index = -1;
                                    for (ArrayList<LiuheBean> liuheBeanArrayList : liuheItems) {
                                        index++;
                                        if (totalNums[index] > 0) {
                                            LHCBetListActivity.Results result = new LHCBetListActivity.Results();
                                            result.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getRule_id();
                                            result.single = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                                            result.quantity = totalNums[index];
                                            result.total = result.single * result.quantity;
                                            result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + "-" + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getName();
                                            for (LiuheBean liuheBean : liuheBeanArrayList) {
                                                if (liuheBean.choose) {
                                                    switch (getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) {
                                                        case "lianxiao":
                                                            if (result.odd == null) {
                                                                result.odd = liuheBean.minOdd + "";
                                                            } else {
                                                                if (liuheBean.minOdd < Float.parseFloat(result.odd)) {
                                                                    result.odd = liuheBean.minOdd + "";
                                                                }
                                                            }
                                                            break;
                                                        case "lianwei":
                                                            if (result.odd == null) {
                                                                result.odd = liuheBean.minOdd + "";
                                                            } else {
                                                                if (liuheBean.minOdd > Float.parseFloat(result.odd)) {
                                                                    result.odd = liuheBean.minOdd + "";
                                                                }
                                                            }
                                                            break;
                                                        case "zixuanbuzhong":
                                                        case "zhongyi":
                                                        case "lianma":
                                                            if (result.odd == null) {
                                                                result.odd = liuheBean.odd;
                                                            }
                                                            break;
                                                        default:
                                                            if (result.odd == null) {
                                                                result.odd = liuheBean.odd;
                                                            } else {
                                                                result.odd = result.odd + "," + liuheBean.odd;
                                                            }
                                                            break;
                                                    }
                                                    if (result.number == null) {
                                                        result.number = liuheBean.number;
                                                    } else {
                                                        result.number = result.number + "," + liuheBean.number;
                                                    }
                                                    result.rakeback = liuheBean.rakeback;
                                                }
                                            }
                                            result.type = getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code();
                                            chooses.add(result);
                                        }
                                    }
                                    confirmIfGotoShoppingCar(gotoShoppingcar, chooses);
//                                }
                            } else {
                                Utils.showToast("请选择号码");
                            }
                            break;
                        default:
                            ArrayList<LHCBetListActivity.Results> chooses = new ArrayList<>();
                            int index = -1;
                            for (ArrayList<LiuheBean> liuheBeanArrayList : liuheItems) {
                                index++;
                                for (LiuheBean liuheBean : liuheBeanArrayList) {
                                    if (liuheBean.choose) {
                                        LHCBetListActivity.Results result = new LHCBetListActivity.Results();
                                        if ("zhengma".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                            result.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getRule_id();
                                            result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + "-" + getLotteryDetailResponse.getLayouts().get(mIndex).getName();
                                        } else {
                                            if (getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index) != null) {
                                                if ("qimawuxing".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                                        || "touweishu".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                                        || "sebo".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                                        || "shengxiao".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())
                                                        || "zhengma16".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                                    result.rule_id = liuheBean.rule_id;
                                                } else {
                                                    result.rule_id = getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getRule_id();
                                                }
                                                if ("liangmian".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code()) || "temaab".equals(getLotteryDetailResponse.getLayouts().get(mIndex).getLayout_code())) {
                                                    String suffix = "";
                                                    if (liuheBean.name != null) {
                                                        suffix = liuheBean.name;
                                                    }
                                                    result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + "-" + suffix;
                                                    result.rule_id = liuheBean.rule_id;
                                                } else {
                                                    result.title = getLotteryDetailResponse.getLayouts().get(mIndex).getName() + "-" + getLotteryDetailResponse.getLayouts().get(mIndex).getChildren().get(index).getName();
                                                }
                                            }
                                        }
                                        result.number = liuheBean.number;
                                        result.odd = liuheBean.odd;
                                        result.rakeback = liuheBean.rakeback;
                                        result.single = Integer.parseInt(mBottomOrderLayout.getMoney_and_num().getText().toString());
                                        result.quantity = 1;
                                        result.total = result.single;
                                        chooses.add(result);
                                    }
                                }
                            }
                            if (chooses.size() > 0) {
//                                if (totalMoneys > Float.parseFloat(UserInfo.getAccount())) {
//                                    Utils.showToast("您的余额不足");
//                                } else {
                                    confirmIfGotoShoppingCar(gotoShoppingcar, chooses);
//                                }
                            } else {
                                Utils.showToast("请选择号码");
                            }
                            break;
                    }
                } else {
                    Utils.showToast("请填写金额");
                }
            } else {
                Utils.showToast("当前状态不可购买");
            }
        } else {
            gotoLoginActivity();
        }
    }

    @OnClick({R.id.play_method, R.id.start_prize, R.id.ball_view, R.id.iv_refresh})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ball_view:
                gotoChatRoom(lotteryCode);
                break;
            case R.id.play_method:
                LiuhecaiTypeDialog liuhecaiTypeDialog = new LiuhecaiTypeDialog();
                FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
                fts.setCustomAnimations(R.anim.anim_enter_from_bottom, R.anim.anim_exit_from_bottom, R.anim.anim_enter_from_bottom, R.anim.anim_exit_from_bottom);
                fts.replace(android.R.id.content, liuhecaiTypeDialog);
                fts.addToBackStack("types");
                fts.commitAllowingStateLoss();
                break;
            case R.id.start_prize:
                //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_" + getIntent().getStringExtra("code") + "_itemdetail_recent_drawbtn");
                recentPrize();
                break;
            case R.id.iv_refresh:
                view.setEnabled(false);
                view.setSelected(false);
                view.setVisibility(View.GONE);
                handler.sendEmptyMessageDelayed(WHAT_REFRESH_TIME, 20000);
                viewRefreshAnimation.setVisibility(View.VISIBLE);
                viewRefreshAnimation.playAnimation();
                viewRefreshAnimation.addAnimatorListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animator) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animator) {
                        ivRefresh.setVisibility(View.VISIBLE);
                        viewRefreshAnimation.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animator) {

                    }
                });
                updateAccount(new AfterUpdateAccount() {
                    @Override
                    public void afterUpdateAccount(GetProfileResponse getProfileResponse) {
                        UserInfo.setAccount(getProfileResponse.getUser().getAccount());
                        mBottomOrderLayout.setLoginState();
                    }
                });
                break;
        }
    }

    // SensorEventListener回调方法
    static final int UPDATE_INTERVAL = 100;
    /**
     * 上一次检测的时间
     */
    long mLastUpdateTime;
    /**
     * 上一次检测时，加速度在x、y、z方向上的分量，用于和当前加速度比较求差。
     */
    float mLastX, mLastY, mLastZ;

    /**
     * 摇晃检测阈值，决定了对摇晃的敏感程度，越小越敏感。
     */
    public int shakeThreshold = 3500;

    @Override
    public void onSensorChanged(SensorEvent event) {
        int type = event.sensor.getType();

        if (type == Sensor.TYPE_ACCELEROMETER) {
            long currentTime = System.currentTimeMillis();
            long diffTime = currentTime - mLastUpdateTime;
            if (diffTime < UPDATE_INTERVAL) {
                return;
            }
            mLastUpdateTime = currentTime;
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];
            float deltaX = x - mLastX;
            float deltaY = y - mLastY;
            float deltaZ = z - mLastZ;
            mLastX = x;
            mLastY = y;
            mLastZ = z;
            float delta = (float) (Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / diffTime * 10000);
            // 当加速度的差值大于指定的阈值，认为这是一个摇晃
            if (delta > shakeThreshold && !isShake) {
                startShake();
            }
        }
    }

    private void startShake() {
        if (mBottomOrderLayout.getInclude_state1().getVisibility() == View.VISIBLE) {
            isShake = true;
            Thread thread = new Thread() {
                @Override
                public void run() {
                    super.run();
                    try {
                        //开始震动 发出提示音 展示动画效果
                        mHandler.obtainMessage(START_SHAKE).sendToTarget();
                        Thread.sleep(500);
                        //再来一次震动提示
                        mHandler.obtainMessage(AGAIN_SHAKE).sendToTarget();
                        Thread.sleep(500);
                        mHandler.obtainMessage(END_SHAKE).sendToTarget();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            thread.start();
        }
    }

    private static class MyHandler extends Handler {
        private WeakReference<LiuhecaiDetailActivity> mReference;
        private LiuhecaiDetailActivity mActivity;

        public MyHandler(LiuhecaiDetailActivity activity) {
            mReference = new WeakReference(activity);
            if (mReference != null) {
                mActivity = mReference.get();
            }
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case START_SHAKE:
                    mActivity.mVibrator.vibrate(300);
                    break;
                case AGAIN_SHAKE:
                    mActivity.mVibrator.vibrate(300);
                    break;
                case END_SHAKE:
                    if (mActivity != null) {//整体效果结束, 将震动设置为false
                        mActivity.isShake = false;
                        mActivity.createOneBet();//产生一注
                    }
                    break;
            }
        }

    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case ChooseLotteryActivity.REPONSE_CODE:
                if (data != null) {
                    String code = data.getStringExtra("code");
                    int item_class = data.getIntExtra("item_class", -1);
                    if (!Utils.isEmpty(code) && item_class != -1) {
                        gotoLotteryDetailActivity(code, item_class);
                        finish();
                    }
                }
                break;
        }
    }


    public void gotoLotteryDetailActivity(String code, int index) {//0 其它 1官方2六合3传统
        switch (index) {
            case 1: {
                Intent intent = new Intent(LiuhecaiDetailActivity.this, OfficalLotteryDetailActivity.class);
                intent.putExtra("code", code);
                startActivity(intent);
                break;
            }
            case 2: {
                Intent intent = new Intent(LiuhecaiDetailActivity.this, LiuhecaiDetailActivity.class);
                intent.putExtra("code", code);
                startActivity(intent);
                break;
            }
            case 3: {
                Intent intent = new Intent(LiuhecaiDetailActivity.this, ChuantongcaiActivity.class);
                intent.putExtra("code", code);
                startActivity(intent);
                break;
            }
        }
    }


    /**
     * 获取运营商聊天室开关状态
     */
    public void getRoomStatus() {
        RetrofitBase.getRetrofit().create(GetChatRoomCurrentStatus.class).getResult()
                .compose(RxHelper.<ChatRoomStatus>handleResultReConnection())
                .subscribe(new RxSubscribe<ChatRoomStatus>(this) {
                    @Override
                    protected void _onNext(ChatRoomStatus chatRoomStatus) {
                        if (chatRoomStatus != null) {
                            ChatRoomStatus.DataBean data = chatRoomStatus.getData();
                            if (data != null) {
                                switch (data.getStatus()) {
                                    case ChatRoomStatus.CHAT_ROOM_STATUS_OPEN:
                                        ball_view.setVisibility(View.VISIBLE);
                                        break;
                                    case ChatRoomStatus.CHAT_ROOM_STATUS_CLOSE:
                                        ball_view.setVisibility(View.GONE);
                                        break;
                                }
                            }
                        }
                    }

                    @Override
                    protected boolean showDialog() {
                        return true;
                    }
                });
    }

}